{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import arcpy,json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "us = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "with arcpy.da.SearchCursor(\"./shp/china_simple.shp\",[\"Code\",\"Shape@JSON\"]) as s:\n",
    "    for r in s:\n",
    "        us[r[0]] = r[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"china.json\",\"w\") as f:\n",
    "    json.dump(us,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = 0\n",
    "s = \"\"\n",
    "for row in open(\"./china_simple.gal\"):\n",
    "    if i ==0:\n",
    "        i+=1\n",
    "        continue\n",
    "    r = row.split(\" \")\n",
    "    if i % 2 != 0:\n",
    "        s +=\"{0},\".format(r[0])\n",
    "    else:\n",
    "        for n in r:\n",
    "            s +=\"{0};\".format(n)\n",
    "        s = s[:-1]\n",
    "    i+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1178"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open(\"./china.csv\",\"w\").write(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
